//
//  PhoneCallManager.m
//  20240823
//
//  Created by 张伟 on 2024/8/25.
//

#import "PhoneCallManager.h"

@implementation PhoneCallManager

+ (void)showPhoneNumber:(LJPerson *)person selectPhoneNumber:(nonnull void (^)(NSString * _Nonnull))phoneNumber{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"请选择拨打号码" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    [person.phones enumerateObjectsUsingBlock:^(LJPhone * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        NSString * fullNumber = obj.phone;
        if (obj.label != nil) {
            fullNumber = [NSString stringWithFormat:@"%@：%@",obj.label, obj.phone];
        }
        
        [alert addAction:[UIAlertAction actionWithTitle:fullNumber style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (phoneNumber) {
                phoneNumber(obj.phone);
            }
        }]];
    }];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [ZWTools.currentTopViewController presentViewController:alert animated:true completion:nil];
}

+ (void)callPhoneNumber:(NSString *)number {
    if (!number.length) {
        return;
    }
    [SipManager.sharedManager call:number];
}


@end
